// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import Vue from 'vue'
import App from './App'
import router from './router'
import ElementUI from 'element-ui';
import * as echarts from "echarts";
import axios from 'axios';
import Watermark from './components/waterMark.js';
import 'element-ui/lib/theme-chalk/index.css';
import { Message } from 'element-ui';

Vue.use(ElementUI)
Vue.prototype.$Watermark = Watermark;
Vue.prototype.$echarts=echarts
Vue.prototype.$axios=axios
Vue.config.productionTip = false
Vue.component("helloWorld",{template:`<h1></h1>`})

  router.beforeEach((to,form,next) =>{
    //如果进入到的路由是登录页或者注册页面，则正常展示
    if(to.path == '/' || to.path == '/register' ){
      next();
    }else if( !(localStorage.getItem('id')) ){
      Message.error("还没有登录，请先登录！");
      next('/');     //转入login登录页面，登录成功后会将token存入localStorage
    }else{
      next();
    }
    if (to.path == '/show'||to.path == '/index'||to.path == '/dept'||to.path == '/form'
      ||to.path == '/formList'||to.path == '/transfer'||to.path == '/turn'||to.path == '/confTurn'
      ||to.path == '/newTurn'||to.path == '/formConfig2'){
        if(localStorage.getItem('role')==1){
          next();
        }else{
          next('/info');
        }
    }
  })

new Vue({
  el: '#app',
  router,
  components: { App },
  template: '<App/>'
})
